<%@page import="javax.sound.midi.SysexMessage"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="java.util.*"%>
<%@ page import="javax.servlet.*"%>
<%@ page import="rtp.model.Tarefa"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Listar Tarefa</title>
<link href="css/Estilo.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="/Tarefa/flexigrid/css/flexigrid/flexigrid.css">
<script type="text/javascript" src="/Tarefa/flexigrid/lib/jquery/jquery.js"></script>
<script type="text/javascript" src="/Tarefa/flexigrid/flexigrid.js"></script>
<style>
		
	.flexigrid div.fbutton .add
		{
			background: url(/Tarefa/flexigrid/css/images/add.png) no-repeat center left;
		}	

	.flexigrid div.fbutton .delete
		{
			background: url(/Tarefa/flexigrid/css/images/close.png) no-repeat center left;
		}	

		
</style>
</head>
<body>
<div class="page">
	<%@ include file="header.jsp" %>
	<div class="main">
		<h1 align="center">Lista de Tarefas Abertas</h1>
		<p>
		<div class="main">
		<table id="flex1"  >
			<% 
			  
			  ArrayList<Tarefa> tarefa = (ArrayList)request.getAttribute("tarefas");
			  Iterator it = tarefa.iterator();
			  
			  while(it.hasNext()) {
				  Tarefa element = (Tarefa) it.next();
				  out.print("<tr id="+element.getId()+">");
				  out.print("<td>" + element.getId()+"</td>");
				  out.print("<td>" + element.getTitulo()+"</td>");
				  out.print("<td>" + element.getPrazo()+"</td>");
				  out.print("<td>" + element.getDetalhes()+"</td>");
				  out.print("<td>" + element.getResponsavel()+"</td>");
				  out.print("<td>" + element.getStatus()+"</td>");
				  out.print("<td>" + element.getDtConclusao()+"</td>");
				  out.print("<td>" + element.getSolucao()+"</td>");	  
				  out.print("</tr>");
			  }
			%>	
		</table>
		</div>
		
		<script type="text/javascript">
		
			$('#flex1').flexigrid({
			colModel : [
						{display: 'ID', name : 'A', width : 40, sortable : true, align: 'center'},
						{display: 'Titulo', name : 'B', width : 180, sortable : true, align: 'center'},
						{display: 'Prazo', name : 'C', width : 120, sortable : true, align: 'center'},
						{display: 'Detalhes', name : 'D', width : 120, sortable : true, align: 'center'},						
						{display: 'Responsavel', name : 'E', width : 120, sortable : true, align: 'center'},
						{display: 'Status', name : 'F', width : 130, sortable : true, align: 'center'},
						{display: 'Data Conclusao', name : 'G', width : 120, sortable : true, align: 'center'},
						{display: 'Solucao', name : 'H', width : 120, sortable : true, align: 'center'}
						],
			buttons : [
						{name: 'Concluir Tarefa', bclass: 'add', onpress : concluir},
						{separator: true}
						],						
			height:'auto',
			title: 'Abertas',	
			showTableToggleBtn: true,
			width: 'auto',
			striped:false,
			singleSelect: true
			});
		
			function concluir(com,grid){
			    if ($('.trSelected',grid).length > 1){
			    	alert('Escolher apenas um item');
			    	return false;
			    }
			    
			    if ($('.trSelected',grid).length < 1){
			    	alert('Favor selecionar a tarefa!');
			    	return false;
			    }
			    
			      var IDs = "";
			      $('.trSelected',grid).each(  
				  	function(){
				  		IDs = this.id;
				    }
				  );
			      confirmado = confirm('Concluir tarefa ' + IDs + '?');
			      if (confirmado){
			  		  document.getElementById("ids").value = IDs;
			  		  document.getElementById("form2servlet").submit();
			  	  }
			}
		</script>
		</p>		
	</div>
</div>
<form method="post" action="EscolherTarefas.do" id="form2servlet">
	<input type="hidden" name="ids" id="ids" value="" /> 
</form>
<%@ include file="footer.jsp" %>
</body>
</html>